﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using hedefgrup.reports.renault.calculators;
using hedefgrup.reports.renault;
using System.Text;
using hedefgrup.reports.renault.definitions;
using System.Collections.Generic;
using hedefgrup.reports.renault.sorting;

public partial class jscommand_salespeoplelist : reportPage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        base.initialize();

        Response.Write("clearDropDown('sp');");

        DataTable dataTable = dataCache.getDataTable(base.getDataCache().dataTableName);

        DataRow[] rows = dataTable.Select("BAYII = '" + base.getDealer().getCode() + "'");

        List<string> salesPeople = new List<string>();

        foreach (DataRow row in rows)
        {
            string salesPerson = row["SATICI"].ToString();
            if (!string.IsNullOrEmpty(salesPerson))
            {
                if (!salesPeople.Contains(salesPerson))
                {
                    salesPeople.Add(salesPerson);
                }
            }
        }

        StringBuilder responseContent = new StringBuilder();

        appendSalesPerson("", "Tümü", responseContent);

        if (salesPeople.Count == 0)
        {
            responseContent.Append("setEnableState('sp', false);");
        }
        else
        {
            responseContent.Append("setEnableState('sp', true);");
            foreach (string salesPerson in salesPeople)
            {
                appendSalesPerson(salesPerson, salesPerson, responseContent);
            }
        }
        Response.Write(responseContent);
    }

    private void appendSalesPerson(string code, string name, StringBuilder htmlBuilder)
    {
        htmlBuilder.AppendFormat("addOption('sp', '{0}', '{1}', {2});", code, name, code == base.salesPerson ? "1" : "0");
    }


}
